package com.wgj.android.ui.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.jiaai.xui.utils.http.ListHttpCallBack;
import com.jiaai.xui.utils.http.XHttp;
import com.jiaai.xui.view.widget.XToast;
import com.wgj.android.R;
import com.wgj.android.adapter.MyAgencyAdapter;
import com.wgj.android.adapter.MyShopStoreAdapter;
import com.wgj.android.entity.ShopAgency;
import com.wgj.android.entity.ShopStore;
import com.wgj.android.http.WGJAPI;
import com.wgj.android.utils.CacheUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyAgencyActivity extends AppCompatActivity {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    private MyAgencyAdapter adapter;
    private List<ShopAgency> shopAgencies=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_agency);
        ButterKnife.bind(this);
        adapter = new MyAgencyAdapter(recyclerView, shopAgencies);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
        loadShopStores();
    }

    private void loadShopStores() {
        XHttp.obtain().get(WGJAPI.BASEURL + "shop/myAgentShop?userId=" + "232100000010", null, new ListHttpCallBack<ShopAgency>() {
            @Override
            public void onSuccess(List<ShopAgency> list) {
                shopAgencies.clear();
                shopAgencies.addAll(list);
                adapter.notifyDataSetChanged();

            }

            @Override
            public void onFailed(int i, String s, boolean b) {
                XToast.error("异常");
            }
        });
    }
}
